<?php
function createThumbi( $pathToImages, $pathToThumbs, $thumbWidth ) 
{
  $dir = opendir( $pathToImages );
  while (false !== ($fname = readdir( $dir ))) {
    $info = pathinfo($pathToImages . $fname);
    if ( strtolower($info['extension']) == 'jpg' ) 
    {
      echo "Creating thumbnail for {$fname} <br />";
      flush();
      
      $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
      $width = imagesx( $img );
      $height = imagesy( $img );
      $new_width = $thumbWidth;
      $new_height = floor( $height * ( $thumbWidth / $width ) );
      $tmp_img = imagecreatetruecolor( $new_width, $new_height );
      imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
      imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
    }else if( strtolower($info['extension']) == 'png'){
     echo "Creating thumbnail for {$fname} <br />";
     flush();
     $img = imagecreatefrompng( "{$pathToImages}{$fname}" );
     $width = imagesx( $img );
     $height = imagesy( $img );
     $new_width = $thumbWidth;
     $new_height = floor( $height * ( $thumbWidth / $width ) );
     $tmp_img = imagecreatetruecolor( $new_width, $new_height );
     imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
     imagepng( $tmp_img, "{$pathToThumbs}{$fname}" );
   }
 }
 closedir( $dir );
}

  $folder='backbar';
  createThumbi("./images/".$folder."/","./images/".$folder."/thumb/",300);
  $folder='banner';
  createThumbi("./images/".$folder."/","./images/".$folder."/thumb/",300);
  $folder='body';
  createThumbi("./images/".$folder."/","./images/".$folder."/thumb/",300);
  $folder='byline';
  createThumbi("./images/".$folder."/","./images/".$folder."/thumb/",300);
  $folder='footer';
  createThumbi("./images/".$folder."/","./images/".$folder."/thumb/",300);
  $folder='innerbody';
  createThumbi("./images/".$folder."/","./images/".$folder."/thumb/",300);

?>